package cn.edu.haust.Mqdemo.services;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Component;

import javax.jms.Destination;

/**
 * Created by 17670 on 2017/9/13.
 */
@Component("mqTest")
public class MqTest {
    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    public void send(Destination destination,String message){
        jmsMessagingTemplate.convertAndSend(destination,message);
    }

    //定义一个监听者
    @JmsListener(destination = "myQueue")
    public void listen(String message){
        System.out.println(message);
    }
    @JmsListener(destination = "mytopic")
    public void listenTopic(String message){
        System.out.println(message+"订阅者1号");
    }
    @JmsListener(destination = "mytopic")
    public void listenTopic1(String message){
        System.out.println(message+"订阅者2号");
    }
}
